/**
 * Copyright(c) 2010 Ceno Techonologies Co., Ltd.
 *
 * History:
 *   15-8-6 上午10:24 Created by piaohh
 */
package com.jade.bss.base.provision.customer;

import com.jade.bss.base.BssException;
import com.jade.bss.base.customer.UserMapping;

/**
 * 保存企业信息到数据库
 * @author <a href="mailto:Administrator@ceno.cn">piaohh</a>
 * @version 1.0 15-8-6 上午10:24
 */
public class AddEnterpriseValve extends AbstractCustomerValve
{
    @Override
    protected void doHandle(CustomerContext context)
            throws BssException
    {
        long customerId = customerManager.addCustomer(context.getCustomer());
        Object object = context.getObject("user_mapping");
        if (object != null) {
            if (object instanceof UserMapping) {
                mappingManager.addMapping(customerId, ((UserMapping) object).getAppCode(),
                        ((UserMapping) object).getUserId());
            }
            else {
                UserMapping[] mappings = (UserMapping[]) object;
                for (UserMapping mapping : mappings) {
                    mappingManager.addMapping(customerId, mapping.getAppCode(), mapping.getAppCode());
                }
            }
        }
    }
}
